#
# $Header: mkinitramfs-ll/hooks/mkswap.zfs               Exp $
# $Author: (c) 2011-6 tokiclover <tokiclover@gmail.com>  Exp $
# $License: 2-clause/new/simplified BSD                  Exp $
# $Version: 0.14.7 2014/11/11 12:33:03                   Exp $
#

mkswap_zfs() {
	usage() {
	cat <<-EOH
 usage: mkswap_zfs: [options] -s|--size <size> pool/volume
   -o|--option <opt>   zpool-option
   -b|--bs 8k          block-size, default 4k
EOH
	}
	if ! test $# -ge 2; then
		usage
		return 1
	fi
	local _bs _opt _size
	while test $# > 1; do
		case "$1" in
			(-b|--bs)
				_bs=$2
				shift 2;;
			(-o|--option)
				_opt="$_opt -o $2"
				shift 2;;
			(-s|--size)
				_size=$2
				shift;;
			(-h|--help) usage;;
		esac
	done
	if ! test $# -eq 1 -a -n "$1" -a -n "$_size"; then
		usage
		return 2
	fi

	zfs create -o sync=always -o primarycache=metadata \
		-o secondarycache=none $_opt -b ${_bs:-4k} -V $_size $1
}

[ "${0##*/}" = "mkswap-zfs" ] && mkswap_zfs "$@"

#
# vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4:
#
